package com.cloudfun.campusshare.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.cloudfun.campusshare.common.model.dto.WeChatPaymentNotifyDTO;
import com.cloudfun.campusshare.entity.WeChatPaymentEntity;
import com.cloudfun.campusshare.repo.WeChatPaymentEntityRepo;
import com.cloudfun.campusshare.service.WeChatPaymentService;
import com.cloudfun.campusshare.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * Created by Huqin on 2020/4/21
 */
@Slf4j
@Service
public class WeChatPaymentServiceImpl implements WeChatPaymentService {

    @Autowired
    private WeChatPaymentEntityRepo weChatPaymentEntityRepo;

    @Override
    public void create(String customerId, String orderId, WeChatPaymentNotifyDTO notifyDTO) {
        WeChatPaymentEntity weChatPaymentEntity = new WeChatPaymentEntity();
        BeanUtil.copyProperties(notifyDTO, weChatPaymentEntity, "timeEnd");
        weChatPaymentEntity.setCustomerId(customerId);
        weChatPaymentEntity.setOrderId(orderId);
        weChatPaymentEntity.setTimeEnd(LocalDateTime.parse(notifyDTO.getTimeEnd(), DateUtil.DATE_TIME_FORMATTER_NO_SEP));
        weChatPaymentEntityRepo.save(weChatPaymentEntity);
    }

}
